
{
  //大括号{}配let才是块级作用域
  let a=1
}

let a=10;
if(a){
	let a=1;
	console.log(a);
}

let obj={
	n1:10,
	n2:20
};
let n1 = obj["n1"];
let n2 = obj.n2;
console.log(n1,n2);


let ary = [1,2,3,4,5,6,7,8];
console.log(ary.copyWithin(5,2,6));

var ary3 = [1,,,2,,];
console.log(ary3.map(function(item){
	return item;
}));

let ary1 = [1,2,3,31.3,112,234];
console.log(Math.max(...ary1));

let a1 = [1,2,3], a2 = [4,5,6];
console.log(a1.concat(a2));
console.log([...a1,...a2]);
let school = {name:'zf'};
let my = {age:18}
let all = {...school,...my};
console.log(all)

box.onclick = ()=>{
	console.log(this);
}

//并集，交集，差集
let arr1 = [1,2,3,4,5,6,1,2], arr2 = [2,3,4,7,8,9,2,3];
function bj(arr1,arr2){
	return [...new Set([...arr1,...arr2])];
}
console.log(bj(arr1,arr2));

function jj(arr1,arr2){
	return [...new Set(arr1)].filter((item)=>{
		return arr2.includes(item);
		// return new Set(arr2).has(item);
	});
}
console.log(jj(arr1,arr2));

function cj(arr1,arr2){
	return bj(arr1,arr2).filter((item)=>{
		return !(jj(arr1,arr2).includes(item));
	});

}
console.log(cj(arr1,arr2));

//集合，不能放重复的东西
let s = new Set([1,2,3,3,4,2]);
s.add(5);
s.delete(5);
s.values();

//映射
let m = new Map();
m.set('name','123');
let obj4 = {name:1};
m.set(obj4,'456');//这个obj的引用空间被set所引用
obj = null;//把obj清空，这个空间还是在的
console.log(m);//{ 'name' => '123', { name: 1 } => '456' }

//WeakMap  key只能是对象
let m1 = new WeakMap();//v8引擎的垃圾回收
let obj5 = {name:1};
m1.set(obj5,'456');
obj = null;
console.log(m1.get(obj5));



function deepClone(obj,hash = new WeakMap()){
  if(obj == null) return obj;
  if(obj instanceof Date) return new Date(obj);
  if(obj instanceof RegExp) return new RegExp(obj);
  if(typeof obj !== 'object') return obj;
  if(hash.has(obj)) return hash.get(obj);//如果WeakMap中有对象就返回上次拷贝的结果
  let cloneObj = new obj.constructor;
  //如果是对象把他放到WeakMap中，如果再拷贝这个对象，它就已经存在了，直接返回即可
  hash.set(obj,cloneObj);
  for(let key in obj){
    if(obj.hasOwnProperty(key)){
      cloneObj[key] = deepClone(obj[key],hash);
    }
  }
  return cloneObj
}
let obj3 = {name:'abc',age:{a:18}}
obj3.xxx = obj3;//循环引用
let n = deepClone(obj3)
console.log(n)
